package com.weharvest.edu.converter;

import com.weharvest.edu.entity.BackstageRole;
import com.weharvest.edu.view.BackstageRoleView;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class BackstageRole2OBackstageRoleView {
    /**
     * 单独转换
     * @param backstageRole
     * @return
     */
    public static BackstageRoleView converter(BackstageRole backstageRole){
        BackstageRoleView backstageRoleView=new BackstageRoleView();
        BeanUtils.copyProperties(backstageRole,backstageRoleView);
        return backstageRoleView;
    }

    /**
     * 集合转换
     * @param backstageRoleList
     * @return
     */
    public static List<BackstageRoleView> converter(List<BackstageRole>backstageRoleList){
        List<BackstageRoleView>backstageRoleViewList=
                backstageRoleList.stream().map(e -> converter(e)).collect(Collectors.toList());
        return backstageRoleViewList;
    }

    /**
     * 集合转换 +分页
     * @param backstageRoleList
     * @return
     */
    public static List<BackstageRoleView> converter(Page<BackstageRole> backstageRoleList){
        List<BackstageRoleView> backstageRoleViewList = new ArrayList<>();
        for(BackstageRole backstageRole : backstageRoleList.getContent()){
            BackstageRoleView backstageRoleView = new BackstageRoleView();
            BeanUtils.copyProperties(backstageRole,backstageRoleView);
            backstageRoleViewList.add(backstageRoleView);
        }
        return backstageRoleViewList;
    }
}
